using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
namespace MicroMsg.UI.UserContrl
{
	public class WhatsNew : UserControl
	{
		public const string bHasSeenWhatsNewKey = "bHasSeenWhatsNew";
		public const string nVersionNumKey = "nVersionNumKey";
		private const string ScrollingState = "Scrolling";
		private const string NotScrollingState = "NotScrolling";
		private const int cNAniDur = 500;
		private const int cNAniStartTime = 500;
		private const int cNAniGap = 200;
		private const int cNAniPageIndex = 6;
		private ModeDialogHelper mDlgHelper;
		public DlgReturnEvent ReturnEvent;
		private int mNPivotItemCount;
		private WhatsNewKind mWhatsNewKind;
		private Point mStartPoint = default(Point);
		private bool mBIsSetBackKey;
		private IApplicationBar mBar;
		private PhoneApplicationPage mPage;
		private static WhatsNew sWhatsNew;
		private int mNIndexBefore;
		private MMMessageBox msgBoxExit;
		private object msgBoxLocker = new object();
		private Storyboard mSbPageAni;
		private UIElement[] arrUI;
		internal Grid LayoutRoot;
		internal Pivot pivotWhatsNew;
		internal PivotItem pItem1;
		internal Button LoginTabLayout;
		internal PivotItem pItem2;
		internal PivotItem pItem3;
		internal PivotItem pItem4;
		internal PivotItem pItem5;
		internal PivotItem pItem6;
		private bool _contentLoaded;
		public bool IsScrolling
		{
			get;
			private set;
		}
		private WhatsNew(WhatsNewKind whatsNewKind = WhatsNewKind.NewUser)
		{
			this.InitializeComponent();
			this.mDlgHelper = new ModeDialogHelper(this, false, null, false);
			base.add_Loaded(new RoutedEventHandler(this.WhatsNew_Loaded));
			base.add_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.WhatsNew_ManipulationStarted));
			base.add_ManipulationDelta(new EventHandler<ManipulationDeltaEventArgs>(this.WhatsNew_ManipulationDelta));
			base.add_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.WhatsNew_ManipulationCompleted));
			this.mWhatsNewKind = whatsNewKind;
			if (!R.isChineseCN())
			{
				this.pivotWhatsNew.get_Items().RemoveAt(3);
			}
			this.mNPivotItemCount = this.pivotWhatsNew.get_Items().get_Count();
		}
		private void WhatsNew_Loaded(object sender, RoutedEventArgs e)
		{
			this.hideAppBar();
			this.setScrollHandler();
			this.setBackKeyHandler();
		}
		private void WhatsNew_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
		}
		private void WhatsNew_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			if (e.get_ManipulationOrigin().get_X() > this.mStartPoint.get_X() && this.pivotWhatsNew.SelectedIndex == 0)
			{
				e.Complete();
			}
		}
		private void WhatsNew_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this.mStartPoint = e.get_ManipulationOrigin();
		}
		private void btnSeeNext_Click(object sender, RoutedEventArgs e)
		{
			if (this.pivotWhatsNew.SelectedIndex < this.pivotWhatsNew.get_Items().get_Count())
			{
				this.pivotWhatsNew.SelectedIndex++;
			}
		}
		private void btnSeeNext_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
		}
		private void btnSeeNext_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
		}
		private void btnSeeNext_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
		}
		private void btnSeeNext_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
		}
		private void btnSeeNext_MouseLeave(object sender, MouseEventArgs e)
		{
		}
		private void pivotItem_Click(object sender, RoutedEventArgs e)
		{
			if (this.pivotWhatsNew.SelectedIndex < this.pivotWhatsNew.get_Items().get_Count() - 1)
			{
				this.pivotWhatsNew.SelectedIndex++;
			}
		}
		private void setBackKeyHandler()
		{
			if (this.mBIsSetBackKey)
			{
				return;
			}
			PhoneApplicationPage currPage = this.getCurrPage();
			UIElement arg_1A_0 = Application.get_Current().get_RootVisual();
			if (currPage != null)
			{
				this.mPage.add_BackKeyPress(new EventHandler<CancelEventArgs>(this.mPage_BackKeyPress));
				this.mBIsSetBackKey = true;
			}
		}
		private void unSetBackKeyHandler()
		{
			if (this.mBIsSetBackKey)
			{
				PhoneApplicationPage currPage = this.getCurrPage();
				UIElement arg_19_0 = Application.get_Current().get_RootVisual();
				if (currPage != null)
				{
					this.mPage.remove_BackKeyPress(new EventHandler<CancelEventArgs>(this.mPage_BackKeyPress));
					this.mBIsSetBackKey = false;
				}
			}
		}
		private void hideAppBar()
		{
			if (this.mBar != null)
			{
				this.mBar.set_IsVisible(false);
				return;
			}
			PhoneApplicationPage currPage = this.getCurrPage();
			if (currPage != null && currPage.get_ApplicationBar() != null)
			{
				this.mBar = currPage.get_ApplicationBar();
				currPage.get_ApplicationBar().set_IsVisible(false);
			}
		}
		private PhoneApplicationPage getCurrPage()
		{
			if (this.mPage == null)
			{
				PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
				if (phoneApplicationFrame != null)
				{
					PhoneApplicationPage phoneApplicationPage = phoneApplicationFrame.get_Content() as PhoneApplicationPage;
					if (phoneApplicationPage != null)
					{
						this.mPage = phoneApplicationPage;
					}
				}
			}
			return this.mPage;
		}
		private void show()
		{
			SystemTray.set_IsVisible(false);
			this.hideAppBar();
			this.mDlgHelper.Show();
		}
		public static WhatsNew ShowWhatsNew(WhatsNewKind whatsNewKind = WhatsNewKind.NewUser)
		{
			WhatsNew.sWhatsNew = new WhatsNew(whatsNewKind);
			WhatsNew.sWhatsNew.show();
			return WhatsNew.sWhatsNew;
		}
		private void pivotWhatsNew_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (this.mNIndexBefore == 6)
			{
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.hideAllElement();
				});
			}
			else
			{
				if (this.pivotWhatsNew.SelectedIndex == 6)
				{
					this.StartPageAnimation();
				}
			}
			if (this.pivotWhatsNew.SelectedIndex == this.mNPivotItemCount - 1)
			{
				if (this.mNIndexBefore == 0)
				{
					this.pivotWhatsNew.SelectedIndex = 0;
				}
				else
				{
					this.startHideAnimation();
				}
			}
			this.mNIndexBefore = this.pivotWhatsNew.SelectedIndex;
		}
		private void hide()
		{
			ConfigMgr.setBool("bHasSeenWhatsNew", true);
			this.unSetBackKeyHandler();
			this.mDlgHelper.Hide(null);
			if (this.ReturnEvent != null)
			{
				this.ReturnEvent(null);
			}
			if (this.mBar != null)
			{
				this.mBar.set_IsVisible(true);
				this.mBar = null;
			}
			WhatsNew.sWhatsNew = null;
			this.mPage = null;
			SystemTray.set_IsVisible(true);
		}
		private void setScrollHandler()
		{
		}
		private void OnScrollStateChanging(object sender, VisualStateChangedEventArgs e)
		{
			this.IsScrolling = (e.get_NewState().get_Name() == "Scrolling");
			if (e.get_NewState().get_Name() == "Scrolling")
			{
				return;
			}
			e.get_NewState().get_Name() == "NotScrolling";
		}
		private void mPage_BackKeyPress(object sender, CancelEventArgs e)
		{
			e.set_Cancel(true);
			if (this.msgBoxExit != null)
			{
				base.get_Dispatcher().BeginInvoke(delegate
				{
					lock (this.msgBoxLocker)
					{
						if (this.msgBoxExit != null)
						{
							this.msgBoxExit.Hide(1);
						}
					}
				});
				return;
			}
			if (0 < this.pivotWhatsNew.SelectedIndex)
			{
				this.pivotWhatsNew.SelectedIndex--;
				return;
			}
			if (this.mWhatsNewKind == WhatsNewKind.JustSeeIt)
			{
				this.startHideAnimation();
				return;
			}
			if (ConfigMgr.getBool("Set_Common_ToggleExitComfirm", true))
			{
				lock (this.msgBoxLocker)
				{
					MMMessageBox mMMessageBox = MMMessageBox.Show(strings.MainPage_MsgExitTitle, "", true, strings.COM_Yes, strings.COM_No);
					mMMessageBox.ReturnEvent = new DlgReturnEvent(this.BackKeyDlgReturn);
					return;
				}
			}
			App.ExitProgram();
		}
		public void BackKeyDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0) == 0)
			{
				App.ExitProgram();
			}
			lock (this.msgBoxLocker)
			{
				this.msgBoxExit = null;
			}
		}
		private void StartPageAnimation()
		{
		}
		private void mSbPageAni_Completed(object sender, EventArgs e)
		{
		}
		private void showAllElement()
		{
		}
		private void hideAllElement()
		{
		}
		private void StopPageAnimation()
		{
		}
		private void startHideAnimation()
		{
			this.hide();
		}
		private void sb_Completed(object sender, EventArgs e)
		{
			this.hide();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/LoginViews/WhatsNew.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.pivotWhatsNew = (Pivot)base.FindName("pivotWhatsNew");
			this.pItem1 = (PivotItem)base.FindName("pItem1");
			this.LoginTabLayout = (Button)base.FindName("LoginTabLayout");
			this.pItem2 = (PivotItem)base.FindName("pItem2");
			this.pItem3 = (PivotItem)base.FindName("pItem3");
			this.pItem4 = (PivotItem)base.FindName("pItem4");
			this.pItem5 = (PivotItem)base.FindName("pItem5");
			this.pItem6 = (PivotItem)base.FindName("pItem6");
		}
	}
}
